/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.fraction;

import ohos.agp.components.AttrHelper;
import ohos.agp.components.Component;
import ohos.app.Context;

import com.xuexiang.xui_lib.component.GridLayout;
import com.xuexiang.xuidemo.MyApplication;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.factory.AdapterFactory;
import com.xuexiang.xuidemo.fractionstacklayout.BaseFraction;
import com.xuexiang.xuidemo.page.uilts.ToolsAbility;
import com.xuexiang.xuidemo.provider.GridProviderImpl;
import com.xuexiang.xuidemo.util.Constants;

/**
 * 拓展页面
 *
 * @since 2021-03-22
 */
public class ToolFraction extends BaseFraction implements GridLayout.OnItemClickListener {
    private final int anInt2 = 2;
    private final int anInt3 = 3;

    @Override
    public int getUicontent() {
        return ResourceTable.Layout_fraction_tool;
    }

    @Override
    public void initComponent() {
        Context context = mComponent.getContext();
        GridLayout gridLayout = (GridLayout) mComponent.findComponentById(ResourceTable.Id_grid_layout);
        gridLayout.setSpanCount(anInt3);
        gridLayout.setSpacing(AttrHelper.vp2px(anInt2, context));
        gridLayout.setOnItemClickListener(this);
        GridProviderImpl provider = AdapterFactory.getInstance().getToolAdapter(context);
        gridLayout.setProvider(provider);
    }

    @Override
    public void onItemClick(Component component, int position) {
        String titleName =  new Constants().toolTitle[position];
        ToolsAbility.start(getFractionAbility(), titleName);
    }
}
